package com.course.controller;

import com.course.pojo.Plan;
import com.course.service.PlanService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PlanController {

    private PlanService planService;

    @RequestMapping(value = "plan",method = RequestMethod.POST)
    @ResponseBody
    @PostMapping("/plan")
    public String addPlan(String planid){
        try {
            boolean t = planService.is_account(account);
            if(t){
                planService.addPlan(planid);
                json.put("meg","建立成功");
                json.put("code","200");
            } else{
                json.put("meg","建立失败");
                json.put("code","-1");
            }
        } catch (Exception e) {
            e.printStackTrace();
            json.put("meg","建立失败");
            json.put("code","-1");
        }
        return json.toJSONString();
    }

    public String deletePlan(String planid){
        try{
            boolean a = planService.is_account(account);
            if(a){
                planService.deletePlan(planid);
                json.put("meg","删除成功");
                json.put("code","200");
            } else{
                json.put("meg","删除失败");
                json.put("code","-1");
            }

        }catch(Exception e){
            e.printStackTrace();
            json.put("meg","删除失败");
            json.put("code","-1");
        }
    }
}